package com.rose.redis.high_availability;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Linux搭建Redis哨兵参考：https://www.cnblogs.com/zwcry/p/9134721.html
 *
 * 哨兵模式
 * 1：redisson
 * 配置参考：classpath:redisson-sentinel.yml
 * 参考：https://github.com/redisson/redisson/wiki/2.-%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95#27-%E5%93%A8%E5%85%B5%E6%A8%A1%E5%BC%8F
 *
 * 2：spring-boot-redis
 * 配置参考：application-spring-boot-sentinel.yml
 *
 * @author: zhu.chen
 * @date: 2021/1/6
 * @version: v1.0.0
 */
//@Component
public class TestSentinelCommandLineRuner implements CommandLineRunner {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void run(String... args) throws Exception {
        // TODO 哨兵模式下时，控制台老是显示有错误，为什么？
        stringRedisTemplate.opsForValue().set("age", "11", 1, TimeUnit.DAYS);
        System.out.println("1 : " + stringRedisTemplate.opsForValue().get("age"));
        System.out.println("2 : " + stringRedisTemplate.opsForValue().get("age"));
    }

}
